from torch import nn
import torch
import torchvision

from torchvision import datasets

import torchvision.transforms as transforms
from torch.nn import Conv2d

from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter

dataset_tranforms = transforms.Compose([
    transforms.ToTensor(),
])

# train_set = datasets.CIFAR10(root='./datasets', train=True, download=True, transform=dataset_tranforms)
test_set = datasets.CIFAR10(root='./datasets', train=False, download=True, transform=dataset_tranforms)

test_loader = DataLoader(test_set, batch_size=64, shuffle=True, num_workers=0,drop_last=True)


class Tutui(nn.Module):
    def __init__(self):
        super(Tutui, self).__init__()
        self.conv1 = Conv2d(in_channels=3, out_channels=6, kernel_size=3)
        

    def forward(self, x):
        x = self.conv1(x)
        return x

tutui = Tutui()
writer = SummaryWriter('./logs/dataloader/')
step = 0
for data in test_loader:
    imgs, targets = data
    output = tutui(imgs)
    output = torch.reshape(imgs, (-1, 3, 32, 32))
    writer.add_image('conv2_input_img', imgs, step)
    writer.add_image('conv2_output_img', output, step)
    step += 1

writer.close()

